package xyz.molzhao.performance;

import xyz.molzhao.util.CommonUtil;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class DealThenRunAsyncThreadReuse {
    public static void main(String[] args) {
        // 我们把线程的存活时间设置为0，代表这个线程完成任务后就立马销毁掉自己
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 0, TimeUnit.SECONDS, new SynchronousQueue<>());

        CompletableFuture.runAsync(() -> CommonUtil.createBehavior("A"), threadPoolExecutor)
                .thenRunAsync(() -> CommonUtil.createBehavior("B"), threadPoolExecutor)
                .join();
    }
}
